package thread;

public class ThreadCircle extends Thread{
    private final static Object lock = new Object();
    private String letter;
    private int threadNum;

    private static int circleCount = 0;

    public ThreadCircle(String letter,int threadNum){
        this.letter = letter;
        this.threadNum = threadNum;
    }

    @Override
    public void run(){
        for (int i=0; i<10; i++){
            synchronized (lock){
                while (circleCount % 3 != threadNum){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println(letter);
                circleCount++;
                lock.notifyAll();
            }
        }

    }


    public static void main(String[] args) {
        ThreadCircle t1 = new ThreadCircle("A", 0);
        ThreadCircle t2 = new ThreadCircle("B", 1);
        ThreadCircle t3 = new ThreadCircle("C", 2);
        t1.start();
        t2.start();
        t3.start();
    }
}
